package xyz.robinbingo.effectivejava.chapter02.item01;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.BufferedReader;
import java.io.IOException;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.nio.file.FileStore;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.time.Instant;
import java.util.*;

import static xyz.robinbingo.effectivejava.chapter02.item01.Rank.*;

/**
 * @author Robin
 * @date 2019/03/13 17:59
 **/
@RunWith(SpringRunner.class)
@SpringBootTest
public class Item01 {

    @Test
    public void test00() {
        Date date = Date.from(Instant.now());
        System.out.println(date);
    }

    @Test
    public void test01() {
        Set<Rank> faceCards = EnumSet.of(JACK, QUEEN, KING);
        System.out.println(faceCards);
    }

    @Test
    public void test02() {
        BigInteger prime = BigInteger.valueOf(Integer.MAX_VALUE);
        System.out.println(prime);
    }

    @Test
    public void test03() {
        StackWalker luke = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE);
        luke.forEach(System.out::println);
    }

    @Test
    public void test04() {
        Object newArray = Array.newInstance(Dog.class, 5);
        System.out.println(newArray);
    }

    @Test
    public void test05() throws IOException {
        FileStore fs = Files.getFileStore(Paths.get("D:\\2019-03-15-0.json"));
        System.out.println(fs);
    }

    @Test
    public void test06() throws IOException {
        BufferedReader br = Files.newBufferedReader(Paths.get("D:\\2019-03-15-0.json"));
        System.out.println(br);
    }

    @Test
    public void test07() {

        Enumeration<Complaint> legacyLitany = new Enumeration<>() {
            /**
             * Tests if this enumeration contains more elements.
             *
             * @return {@code true} if and only if this enumeration object
             * contains at least one more element to provide;
             * {@code false} otherwise.
             */
            @Override
            public boolean hasMoreElements() {
                return false;
            }

            /**
             * Returns the next element of this enumeration if this enumeration
             * object has at least one more element to provide.
             *
             * @return the next element of this enumeration.
             * @throws NoSuchElementException if no more elements exist.
             */
            @Override
            public Complaint nextElement() {
                return null;
            }
        };
        List<Complaint> litany = Collections.list(legacyLitany);
        System.out.println(litany);
    }
}
